//
//  SchoolInfoTableViewCell.m
//  Civacrm
//
//  Created by superwu_work on 2017/2/16.
//  Copyright © 2017年 王桂敏. All rights reserved.
//

#import "SchoolInfoTableViewCell.h"

@implementation SchoolInfoTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
        
        [self createView];
    }
    
    return  self;
}

-(void)layoutSubviews {
    [super layoutSubviews];
    
    self.titleLabel.frame = CGRectMake(w(22), 0, w(200), self.height);
    
    self.schoolImage.frame = CGRectMake(kScreenWidth - w(120), h(20), w(100), h(100));
    
    self.detailLabel.frame = CGRectMake(kScreenWidth - w(385), 0, w(365), self.height);
    
    self.lineView.frame = CGRectMake(w(22), self.height -1, kScreenWidth - w(22), 1);
    
}

- (void)configViewWithString:(NSString *)string indexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        [self.schoolImage sd_setImageWithURL:[NSURL URLWithString:string] placeholderImage:[UIImage imageNamed:@"icon_civazhicheng_active"]];
        [self.contentView addSubview:self.schoolImage];
    }
    else if (indexPath.section == 1 && indexPath.row == 0) {
        if (string.length == 19) {
            self.detailLabel.text = [NSString stringWithFormat:@"%@ %@ %@ %@ %@",[string substringWithRange:NSMakeRange(0, 4)],[string substringWithRange:NSMakeRange(4, 4)],[string substringWithRange:NSMakeRange(8, 4)],[string substringWithRange:NSMakeRange(12, 4)],[string substringWithRange:NSMakeRange(16, 3)]];
        }
        else {
            self.detailLabel.text = string;
        }
        
    }
    else if (indexPath.section == 1 && indexPath.row == 1) {
        if ([string isEqual:@""]) {
            self.detailLabel.text = [NSString stringWithFormat:@"￥%.2f元", 0.00];
        }
        else {
          self.detailLabel.text = [NSString stringWithFormat:@"￥%@元", string];
        }
    }
    else if (indexPath.section == 2 && indexPath.row == 0) {
        if (string.length == 11) {
            self.detailLabel.text = [NSString stringWithFormat:@"%@ %@ %@",[string substringWithRange:NSMakeRange(0, 3)],[string substringWithRange:NSMakeRange(3, 4)],[string substringWithRange:NSMakeRange(7, 4)]];
        }
        else {
            self.detailLabel.text = string;
        }
        
    }
    else {
        self.detailLabel.text = string;
    }
    
}

- (void)createView {
    
    self.titleLabel = [UILabel labelWithTitle:@"" frame:CGRectZero font:font(32) textColor:ColorWithHexString(@"4E778F") bgColor:ClearColor];
    _titleLabel.textAlignment = NSTextAlignmentLeft;
    
    self.schoolImage = [[UIImageView alloc] init];

    self.detailLabel = [UILabel labelWithTitle:@"" frame:CGRectZero font:font(28) textColor:ColorWithHexString(@"A0C0D2") bgColor:ClearColor];
    _detailLabel.textAlignment = NSTextAlignmentRight;
    _detailLabel.numberOfLines = 0;
    
    self.lineView = [[UIView alloc] init];
    _lineView.backgroundColor = ColorWithHexString(@"f2f9fa");
    
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.detailLabel];
    [self.contentView addSubview:self.lineView];
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
